package com.zhiwei.codesecurity;

//
//import com.sun.corba.se.spi.activation.Server;
//import com.zhiwei.codesecurity.common.utils.ConfigFileUtil;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.context.support.AbstractApplicationContext;
//import org.springframework.context.support.ClassPathXmlApplicationContext;
//import org.springframework.util.ClassUtils;
//import org.springframework.util.Log4jConfigurer;
//import java.io.FileNotFoundException;
//import java.net.URL;

import com.zhiwei.codesecurity.common.webservice.checkmarx.v7.*;

import javax.xml.ws.BindingProvider;

/**
 * Hello world!
 *
 */
public class App {
//    private static volatile boolean running = true;
//
//    static {
//        String log4jFile = "log4j.properties";
//        long refreshInterval = 4000;
//        String fileName = log4jFile;
//        String location = ConfigFileUtil.findFile(fileName);
//
//        if(null == location){
//            fileName = "properties/" + log4jFile;
//            location = ConfigFileUtil.findFile(fileName);
//        }
//        if(null == location){
//            fileName = "config/" + log4jFile;
//            location = ConfigFileUtil.findFile(fileName);
//        }
//        if(null == location) {
//            fileName = "properties/" + log4jFile;
//            URL resource = ClassUtils.getDefaultClassLoader().getResource(fileName);
//            if(resource != null) {
//                location = resource.getFile();
//            }
//        }
//        if(null == location) {
//            fileName = "config/" + log4jFile;
//            URL resource = ClassUtils.getDefaultClassLoader().getResource(fileName);
//            if(resource != null) {
//                location = resource.getFile();
//            }
//        }
//
//        try {
//            if(null != location) {
//                Log4jConfigurer.initLogging(location, refreshInterval);
//            }
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
//
//    }


    public static void main( String[] args ) {
//        Logger logger = LoggerFactory.getLogger(App.class);
//        try {
//            final AbstractApplicationContext ctx =
//                    new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
//            ctx.registerShutdownHook();
//            Runtime.getRuntime().addShutdownHook(new Thread() {
//                public void run() {
//                    ctx.stop();
//                    ctx.close();
//                    synchronized (App.class) {
//                        running = false;
//                        Server.class.notify();
//                    }
//                }
//            });
//            logger.info("Service start success!");
//        } catch (Exception e) {
//            logger.error(e.getMessage(), e);
//            System.exit(1);
//        }
//
//        synchronized (App.class) {
//            while (running) {
//                try {
//                    App.class.wait();
//                } catch (Throwable e) {
//                }
//            }
//        }

        CxSDKWebService cxSDKWebService = new CxSDKWebService();
        System.out.println("QName: " + cxSDKWebService.getServiceName());
        System.out.println("NamespaceURI: " + cxSDKWebService.getServiceName().getNamespaceURI());
        System.out.println("LocalPart: " + cxSDKWebService.getServiceName().getLocalPart());
        CxSDKWebServiceSoap cxSDKWebServiceSoap = cxSDKWebService.getCxSDKWebServiceSoap();
        BindingProvider bindingProvider = (BindingProvider) cxSDKWebServiceSoap;
        bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                "http://61.147.125.143:1088/cxwebinterface/sdk/cxsdkwebservice.asmx?WSDL");

        CxWSResponseScanStatus scanStatus =
        cxSDKWebServiceSoap.getStatusOfSingleScan("9963667789324432403289028ca0-a7da-4696-af42-fb43b4e2ad91HwodXAL1Hb7PntMCCfbe87wOJjDHfEvuOh71",
                "20002");
        int i = 10;

//        Credentials credentials = new Credentials();
//        credentials.setUser("admin");
//        credentials.setPass("Admin@2018");
//        CxWSResponseLoginData cxWSResponseLoginData;
//        try {
//            cxWSResponseLoginData =
//                    cxSDKWebServiceSoap.login(credentials, 2052);
//            System.out.println("cxWSResponseLoginData.isIsSuccesfull(): " + cxWSResponseLoginData.isIsSuccesfull());
//
//            // 保存SessionID，后继所有操作都将基于这个SessionID进行
//            String cxSession = cxWSResponseLoginData.getSessionId();
//            System.out.println("cxSession: " + cxSession);
//
//            // 获取服务器上的所有扫描配置
//            CxWSResponseConfigSetList cxWSResponseConfigSetList = cxSDKWebServiceSoap.getConfigurationSetList(cxSession);
//            ArrayOfConfigurationSet arrayOfConfigurationSet;
//            if (cxWSResponseConfigSetList.isIsSuccesfull()) {
//                arrayOfConfigurationSet = cxWSResponseConfigSetList.getConfigSetList();
//                System.out.println("arrayOfConfigurationSet: " + arrayOfConfigurationSet.getConfigurationSet());
//            }
//
//            // 获取服务器上的所有团队
//            CxWSResponseGroupList cxWSResponseGroupList = cxSDKWebServiceSoap.getAssociatedGroupsList(cxSession);
//            ArrayOfGroup arrayOfGroup;
//            if (cxWSResponseGroupList.isIsSuccesfull()) {
//                arrayOfGroup = cxWSResponseGroupList.getGroupList();
//                System.out.println("arrayOfGroup: " + arrayOfGroup.getGroup());
//            }
//
//        } catch (Exception ex) {
//            System.out.println(ex.toString());
//        }

    }
}
